package com.study.forumsystemproject.model;
import com.study.forumsystemproject.common.Result;
import com.study.forumsystemproject.common.ResultCode;
import com.study.forumsystemproject.exception.ApplicationException;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
@Data
@Schema(name = "文章类", description = "描述论坛系统中的文章信息")
@Slf4j
public class Article {
    @NotNull(message = "帖子Id不能为空")
    private Long id;
    @Schema(description = "所属版块ID", example = "101")
    private Long boardId;

    @Schema(description = "作者用户ID",  example = "202")
    private Long userId;

    @Schema(description = "文章标题",  example = "如何使用Swagger注解")
    @NotBlank(message = "文章标题不能为空")
    private String title;

    @Schema(description = "浏览次数", example = "1000")
    private Integer visitCount;

    @Schema(description = "回复次数", example = "50")
    private Integer replyCount;

    @Schema(description = "点赞次数", example = "100")
    private Integer likeCount;

    @Schema(description = "文章状态", example = "0") // 假设0为正常，1为禁用等
    private Integer state;

    @Schema(description = "删除标志", example = "0") // 假设0为未删除，1为已删除
    private Integer deleteFlag;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;
    @Schema(description = "是否是作者")
    private Boolean isOwn;

    @Schema(description = "文章内容")
    @NotBlank(message = "文章内容不能为空")
    private String content;
    @Schema(description = "用户信息")
    private User user;
    @Schema(description = "版块信息")
    private Board board;
    @Schema(description = "是否点赞")
    private Integer isUpvote;
    public static void checkNullByArticle(Article article) {
        if(article == null) {
            log.warn(ResultCode.FAILED_PARAMS_VALIDATE.toString());
            throw new ApplicationException(Result.fail(ResultCode.FAILED_CREATE_ARTICLE));
        }
    }

}